package FlowGram.Application.CommandHost.FinchActionListeners;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JTextArea;

import FlowGram.Application.Application;
import FlowGram.Application.IDEWindow.FileHost.CodeEditor;
import FlowGram.Application.Parser.Actions.Control.Repeat;
import FlowGram.Application.Parser.Utility.ClassFinder;

public class RepeatListener extends FinchActionListener {

	JFrame frame;
	
	Repeat rAct;
	
	public RepeatListener(JFrame frame){
		this.frame = frame;
	}
	
	
	@Override
	public void actionPerformed(ActionEvent e) {
		rAct = new Repeat();
		// TODO Auto-generated method stub
		while(true){
			
			String s = (String)JOptionPane.showInputDialog(
			                    frame,
			                    "Repeat x times:\n"
			                    + "x = ",
			                    "Repeat Parameters",
			                    JOptionPane.QUESTION_MESSAGE);
			if(s == null){break;}		//exit if cancel or X is clicked
			int repeatNum = -1;
			try{
				repeatNum = Integer.parseInt(s);
				
				rAct.setNumTimes(repeatNum);

				addCode(rAct);
				
				break;
			}catch(NumberFormatException numE){
				JOptionPane.showMessageDialog(frame,
			    "Please enter a number");
			}
			

			
			
		}
	}

}
